<template>
	<view style="font-size: 40rpx;">
		<view style="margin-top: 40rpx; margin-left: 30%;width: 300rpx;">
			<image :src="baseURL" style="height: 50rpx;width: 60rpx;margin-left: 10px;float: left;"></image>
			<h4 style="margin-top: 20rpx;margin-left: 100rpx;">基本信息</h4>
		</view>
		<view style="width: 120rpx;float: right; margin-top: -60rpx; margin-right: 40rpx;">
			<u-button color="#6eb5f5" shape="circle" class="qrgengg" type="primary" @click="save" >保存</u-button>
		</view>
		<view style="margin-top: 40rpx; width: 90%;margin-left: 50rpx;">
			<u-line color="#898a8b"></u-line>
			<u--form labelPosition="left" :model="user" :rules="rules" ref="uForm">
				<u-form-item label="姓名" prop="user.name" borderBottom ref="item1"  >
					<view style="margin-left: 440rpx;"><u--input v-model="user.name" border="none"  ></u--input>
				</view>
				</u-form-item>
				<u-form-item label="昵称" prop="user.nickname" borderBottom ref="item1">
					<view style="margin-left: 400rpx;">
						<u--input v-model="user.nickname" border="none" ></u--input>
					</view>	
				</u-form-item>
				<u-form-item label="性别" prop="user.sex" borderBottom @click="showSex = true; hideKeyboard()"
					ref="item1">
					<view style="margin-left: 450rpx;">
						<u--input v-model="labelSex" disabled disabledColor="#ffffff" placeholder="请选择性别"
							border="none" ></u--input>
					</view>
				</u-form-item>
				
				
				<view style="margin-left: -30rpx;font-size: 40rpx;">
					<!-- 小功能 -->
					<u-cell-group >
						<u-cell :value=user.telephone size="large" title="手机号"  isLink ></u-cell>
						<u-calendar showLunar  :mode="mode" :minDate="minDate" :monthNum="monthNum"
							@confirm="confirm" @close="close"></u-calendar>
					</u-cell-group>
					<u-cell-group >
						<u-cell :value=user.studentID size="large" title="学号"  isLink ></u-cell>
						<u-calendar showLunar  :mode="mode" :minDate="minDate" :monthNum="monthNum"
							@confirm="confirm" @close="close"></u-calendar>
					</u-cell-group>
					<u-cell-group style="background-color: #ffffff;">
						<u-cell :value=user.birth size="large" title="出生日期" @click="show = true" isLink></u-cell>
						<u-calendar showLunar :show="show" :mode="mode" :minDate="minDate" :monthNum="monthNum"
							@confirm="confirm" @close="close"></u-calendar>
					</u-cell-group>

					<u-cell-group style="background-color: #ffffff;">
						<u-cell :value=user.enterSchoolYear size="large" title="入学年份" @click="showrx = true" isLink></u-cell>
						<u-picker :show="showrx" :columns="columns" @confirm="confirm1" @cancel="cancel1"></u-picker>
					</u-cell-group>
					<u-cell-group style="background-color: #ffffff;">
						<u-cell :value=user.degreeGrade size="large" title="学历等级" @click="showdj = true" isLink></u-cell>
						<u-picker :show="showdj" :columns="columns1" @confirm="confirm2" @cancel="cancel2"></u-picker>
					</u-cell-group>
					<u-cell-group style="background-color: #ffffff;">
						<u-cell :value=user.degreeType size="large" title="学历类型" @click="showlx = true" isLink></u-cell>
						<u-picker :show="showlx" :columns="columns2" @confirm="confirm3" @cancel="cancel3"></u-picker>
					</u-cell-group>
					<u-cell-group style="background-color: #ffffff;">
						<u-cell :value=user.schoolStatu size="large" title="学籍状态" @click="showxj = true" isLink></u-cell>
						<u-picker :show="showxj" :columns="columns3" @confirm="confirm4" @cancel="cancel4"></u-picker>
					</u-cell-group>
				</view>
			</u--form>
			<!-- 选保密的话也不会报错 -->
			<u-action-sheet :show="showSex" :actions="actions" title="请选择性别" 
				@close="showSex = false" @select="sexSelect"></u-action-sheet>
		</view>
	</view>
</template>


<script>
	import { updateWXuserInfoApi } from '../../../api/myModel';
	export default {
		data() {
			return {
				baseURL:this.$baseURL + '/profile/upload/2025/05/10/jibxx_20250507092558A012_20250510150237A031.png',
				showSex: false,
				show: false,
				showrx: false,
				showdj: false,
				showlx: false,
				showxj: false,
				mode: 'single',
				shengr: '',
				minDate: '2004-1-1',
				maxDate: '2020-1-1',
				monthNum: 90,
				ruxue: "",
				xueldj: "",
				xueshlx: "",
				xuej: "",
				labelSex:"",
				/* showxg: true,
				weizhi: 10075, */
				columns: [
					['2019', '2020', '2021', '2022', '2023', '2024', '2025']
				],
				columns1: [
					['大专', '本科', '研究生']
				],
				columns2: [
					['在校生', '已毕业']
				],
				columns3: [
					['已注册学籍', '毕业无学籍']
				],


				//后端反过来的数据 
				user: {
					avatar: '',//头像
					birth: "",//出生日期
					degreeGrade: "",//学历等级
					degreeType: "",//学历类型
					enterSchoolYear: "",//入学日期
					name: '',//姓名
					nickname: "",//昵称
					schoolStatu: "",//学籍状态
					sex: 0,
					studentID: "",
					telephone: ""
				},
				
		
				// model1: {
				// 	userInfo: {
				// 		name: '',
				// 		sex: '',
				// 		shouj: '',
				// 		xueh: '1223787238',
				// 		youx: '',
				// 		nicheng: '游客',
				// 	},
				// },
				actions: [{
						name: '男',
						sex:0
					},
					{
						name: '女',
						sex:1
					}
				],
				rules: {
					'userInfo.name': {
						type: 'string',
						required: false,
						message: '请填写姓名',
						trigger: ['blur', 'change']
					},
					'userInfo.sex': {
						type: 'string',
						max: 1,
						required: true,
						message: '请选择男或女',
						trigger: ['blur', 'change']
					},
					'userInfo.shouj': {
						type: 'string',
						required: true,
						message: '请填写手机号',
						trigger: ['blur', 'change']
					},
					'userInfo.xueh': {
						type: 'string',
						required: true,
						message: '请填写学号',
						trigger: ['blur', 'change']
					},
					'userInfo.youx': {
						type: 'string',
						required: true,
						message: '请填写邮箱',
						trigger: ['blur', 'change']
					},
				},
				radio: '',
				switchVal: false
			};


		},
		/* onShow() {
			if (showxg == true) {
				this.isLogin = false;
			} else {
				this.isLogin = true;
			}
		}, */

		onLoad(option) {
			this.user=JSON.parse( decodeURIComponent(option.user))
			if(this.user.sex==0){
				this.labelSex="男"
			}else if(this.user.sex==1){
				this.labelSex="女"
			}
			
		},

		methods: {
			save(){
				updateWXuserInfoApi(this.user).then((res)=>{
					if(res.code=="200"){
						// 现在修改成功后页面直接跳转，用户没法看修改成功这个弹框
						// 你看看你能不能想办法让用户知道修改成功
						uni.showToast({
							title: '修改成功',
							icon: 'success',
							duration: 2000
						});
						setTimeout(()=>{
							uni.reLaunch({
								url: '/pages/myModel/my/my'
							});
						},1500)
						
						
					}else{
						uni.showToast({
							title: res.msg,
							icon: 'none',
							duration: 2000
						});
						
					}
					
					
					
				})
			},
			sexSelect(e) {
				// 根据值返回数组对应的索引  用于实现 男对应0  1对应女
				console.log(e)
				this.user.sex = e.sex
				this.labelSex=e.name
				console.log(this.user.sex)
				// 这个不知道是干什么用的
				this.$refs.uForm.validateField('userInfo.sex')
			},
			
			
			//修改出生日期 
			confirm(e) {
				this.show = !this.show;
				this.user.birth=e[0];
			},

			// 入学年份
			confirm1(e) {
				console.log(e.value);
				this.user.enterSchoolYear = String(e.value);
				this.showrx = !this.showrx;
			},
			// 学历等级
			confirm2(e) {
				console.log(e.indexs);
				this.user.degreeGrade = String(e.value);
				this.showdj = !this.showdj;

			},
			// 学历类型
			confirm3(e) {
				console.log(e);
				this.user.degreeType = String(e.value);
				this.showlx = !this.showlx;
			},
			// 学籍状态
			confirm4(e) {
				console.log(e);
				this.user.schoolStatu = String(e.value);
				this.showxj = !this.showxj;
			},

			close(e) {
				this.show = !this.show;

			},
			cancel1(e) {
				this.showrx = !this.showrx;

			},
			cancel2(e) {
				this.showdj = !this.showdj;

			},
			cancel3(e) {
				this.showlx = !this.showlx;

			},
			cancel4(e) {
				this.showxj = !this.showxj;

			},
			

		},
		onReady() {
			//如果需要兼容微信小程序，并且校验规则中含有方法等，只能通过setRules方法设置规则。
			this.$refs.uForm.setRules(this.rules)
		},
	};
</script>

<style lang="scss" scoped>
	.title {
		color: $u-primary;
		text-align: center;
		padding: 20rpx 0 0 0;
	}

	.u-form-item {
		font-size: 35rpx;
	}

	.genggai {
		margin-top: 20rpx;
		width: 270rpx;
		z-index: 10075;
	}

	.qrgengg {
		margin-top: 20rpx;

	}
	.u-cell-group{
		background-color: #ffffff;
	}
	
</style>